package com.controller;

import com.core.base.BaseController;
import com.core.base.BaseService;
import com.core.model.PageData;
import com.core.response.ResponseResult;
import com.model.jpa.Users;
import com.service.IUsersService;
import com.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;


@Api(value = "user表的增删改查")
@RestController
@RequestMapping(value = "/users")
public class UsersController extends BaseController<Users,Long> {

    @Autowired
    private IUsersService iUsersService;


    @Override
    public BaseService<Users,Long> getService() {
        return (BaseService<Users, Long>) iUsersService;
    }

    /**1.登陆方法**/
    @PostMapping(value = "login")
    public ResponseResult login(@RequestBody Users users) {

        return iUsersService.login(users.getUserName(),users.getPassword());
    }

    /**2.增加一名Users **/
    @GetMapping(value = "add_users")
    public ResponseResult addUsers(Users users){

        return iUsersService.addUsers(users);
    }

    /**3.根据用户名查询一个users**/
    @PostMapping(value = "get_info_byUserName")
    public ResponseResult getByUserName(String userName){

        return iUsersService.getByUserName(userName);
    }

    /**根据id 查询一名员工**/
    @PostMapping(value = "get_info_byId")
    public ResponseResult getById(Long id){

        Users users = iUsersService.getById(id);
        return ResponseResult.success(users);
    }
    /**修改users信息**/
    @GetMapping(value = "update_users_info")
    public ResponseResult updateUsersInfo(Users users){

        return iUsersService.updateUsersInfo(users);
    }

    /**根据id删除一名users**/
    @PostMapping(value = "delete_users")
    public ResponseResult deleteUsers(Long[]ids){

        return iUsersService.deleteUsers(ids);
    }

    /**根据真名分页查询出users**/
    @PostMapping(value = "select_users")
    public ResponseResult selectUsers( @RequestParam("realName") String realName,
                                       @RequestParam(value = "page", defaultValue = "0") Integer page,
                                       @RequestParam(value = "size", defaultValue = "10") Integer size){

        PageRequest pageRequest = new PageRequest(page,size);
        Page<Users> usersPage = iUsersService.selectUsers(realName,pageRequest);
        return ResponseResult.success(usersPage.getContent());
    }


}
